﻿using System;

namespace H.Types
{
    /// <summary>
    /// 大漠颜色格式:颜色-偏色
    /// </summary>
    [Serializable]
    public struct RGB2
    {
        /// <summary>
        /// 主要颜色值
        /// </summary>
        public RGB Color;

        /// <summary>
        /// 偏色值
        /// </summary>
        public RGB DeletaColor;

        /// <summary>
        /// 初始化一个大漠颜色
        /// </summary>
        /// <param name="colorex"></param>
        public RGB2(string colorex)
        {
            string[] pieces = colorex.Split('-');
            if (pieces.Length > 0)
            {
                Color = new RGB(pieces[0]);
                if (pieces.Length > 1)
                {
                    DeletaColor = new RGB(pieces[1]);
                }
                else
                {
                    DeletaColor = new RGB(0);
                }
            }
            else
            {
                throw new FormatException("大漠颜色不合法");
            }
        }

        /// <summary>
        /// 打印颜色
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return $"{Color}-{DeletaColor}";
        }
    }
}
